home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / opengl / xlib / intro.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  2.1 KB  |  72 lines

  1. /*
  2.  * Copyright 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include <GL/glx.h>
  18. #include <GL/gl.h>
  19. #include <unistd.h>
  20.  
  21.  
  22. static int attributeList[] = { GLX_RGBA, None };
  23.  
  24. static Bool WaitForNotify(Display *d, XEvent *e, char *arg) {
  25.     return (e->type == MapNotify) && (e->xmap.window ==    (Window)arg);
  26. }
  27.  
  28. int main(int argc, char    **argv)    {
  29.     Display *dpy;
  30.     XVisualInfo    *vi;
  31.     Colormap cmap;
  32.     XSetWindowAttributes swa;
  33.     Window win;
  34.     GLXContext cx;
  35.     XEvent event;
  36.  
  37.     /* get a connection    */
  38.     dpy    = XOpenDisplay(0);
  39.  
  40.     /* get an appropriate visual */
  41.     vi = glXChooseVisual(dpy, DefaultScreen(dpy), attributeList);
  42.  
  43.     /* create a    GLX context */
  44.     cx = glXCreateContext(dpy, vi, 0, GL_TRUE);
  45.  
  46.     /* create a    colormap */
  47.     cmap = XCreateColormap(dpy,    RootWindow(dpy,    vi->screen),
  48.                vi->visual, AllocNone);
  49.  
  50.     /* create a    window */
  51.     swa.colormap = cmap;
  52.     swa.border_pixel = 0;
  53.     swa.event_mask = StructureNotifyMask;
  54.     win    = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0,    100, 100,
  55.             0, vi->depth, InputOutput, vi->visual,
  56.             CWBorderPixel|CWColormap|CWEventMask, &swa);
  57.     XMapWindow(dpy, win);
  58.     XIfEvent(dpy, &event, WaitForNotify, (char*)win);
  59.  
  60.     /* connect the context to the window */
  61.     glXMakeCurrent(dpy,    win, cx);
  62.  
  63.     /* clear the buffer    */
  64.     glClearColor(1,1,0,1);
  65.     glClear(GL_COLOR_BUFFER_BIT);
  66.     glFlush();
  67.  
  68.     /* wait a while */
  69.     sleep(7);
  70. }
  71.  
  72.